package callback;




/**
*
* Description:
* @author admin
* 2017年2月10日下午18:04:07
*/

import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttMessage;

import youwen.Mqtt.MqttServerTest;



public final class MqttServerCallback implements MqttCallback {

   public void connectionLost(Throwable cause) {
       //连接丢失后，一般在这里面进行重连
       System.out.println("mqttserver连接断开，做重连....");
       MqttServerTest.MqttServer.setIsConnect(false);//告诉连接失败,好做重连
   }

   public void deliveryComplete(IMqttDeliveryToken token) {
	   //发布的消息有客户端收到这里自动执行
	   
       //System.out.println("deliveryComplete---------" + token.isComplete());
   }

   public void messageArrived(String topic, MqttMessage message) throws Exception {
       // subscribe后得到的消息会执行到这里面
       System.out.println("消息主题 : " + topic);
       System.out.println("消息Qos : " + message.getQos());
       String mString = new String(message.getPayload());
       System.out.println("消息内容 : " +mString ); 
   }
}
